package com.charger.utils;

import com.charger.common.utils.DateUtils;

import java.text.ParseException;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

/**
 * @ClassName BeforeDateList
 * @Description TODO
 * @Author QinKunPeng
 * @Date 2024年11月23日 17:23
 * @Version 1.0
 */
public class QDateUtils {
    public static List<String> getBefore(Integer day, Date date) {
        List<String> list = new ArrayList<>();
        for (int i = 0; i < day; i ++){
            String s = DateUtils.parseDateToStr("yyyy-MM-dd", new Date(date.getTime() - 1000 * 60 * 60 * 24 * i));
            list.add(s);
        }
        return list;
    }

    public static String beforeTime(Integer minutes, Date date) {
        String time = null;
        time = DateUtils.parseDateToStr("HH:mm:ss", new Date(date.getTime() - 1000 * 60 * minutes));
        return time;
    }

    public static List<String> getTime(){
        List<String> list = new ArrayList<>();
        list.add("00:00");
        list.add("01:00");
        list.add("02:00");
        list.add("03:00");
        list.add("04:00");
        list.add("05:00");
        list.add("06:00");
        list.add("07:00");
        list.add("08:00");
        list.add("09:00");
        list.add("10:00");
        list.add("11:00");
        list.add("12:00");
        list.add("13:00");
        list.add("14:00");
        list.add("15:00");
        list.add("16:00");
        list.add("17:00");
        list.add("18:00");
        list.add("19:00");
        list.add("20:00");
        list.add("21:00");
        list.add("22:00");
        list.add("23:00");
        return list;
    }

    public static String[] weeks(){
        return new String[]{"周日", "周一", "周二", "周三", "周四", "周五", "周六"};
    }

    public static String getCurrentWeekDay() throws ParseException {
        String res = null;
        Calendar cald = Calendar.getInstance();
        int i = cald.get(Calendar.DAY_OF_WEEK);
        if (i >= 2){
            Date date = new Date(new Date().getTime() - 1000 * 3600 * 24 * (i - 2));
            String s = DateUtils.parseDateToStr("yyyy-MM-dd", date);
            Date date1 = DateUtils.parseDate(s, "yyyy-MM-dd");
            res = DateUtils.parseDateToStr("yyyy-MM-dd HH:mm:ss", date1);
        }else if (i == 1){
            Date date = new Date(new Date().getTime() - 1000 * 3600 * 24 * 8);
            String s = DateUtils.parseDateToStr("yyyy-MM-dd", date);
            Date date1 = DateUtils.parseDate(s, "yyyy-MM-dd");
            res = DateUtils.parseDateToStr("yyyy-MM-dd HH:mm:ss", date1);
        }
        return res;
    }

    public static String getFirstDayOfMonth() throws ParseException {
        Calendar cald = Calendar.getInstance();
        int day = Calendar.getInstance().get(Calendar.DAY_OF_MONTH);
        cald.add(Calendar.DAY_OF_MONTH, -(day - 1));
        Date date = cald.getTime();
        String s = DateUtils.parseDateToStr("yyyy-MM-dd", date);
        Date date1 = DateUtils.parseDate(s, "yyyy-MM-dd");
        String res = DateUtils.parseDateToStr("yyyy-MM-dd HH:mm:ss", date1);
        return res;
    }

    public static String getFirstDayOfYear() throws ParseException {
        Calendar cald = Calendar.getInstance();
        int day = Calendar.getInstance().get(Calendar.DAY_OF_YEAR);
        cald.add(Calendar.DAY_OF_YEAR, -(day - 1));
        Date date = cald.getTime();
        String s = DateUtils.parseDateToStr("yyyy-MM-dd", date);
        Date date1 = DateUtils.parseDate(s, "yyyy-MM-dd");
        String res = DateUtils.parseDateToStr("yyyy-MM-dd HH:mm:ss", date1);
        return res;
    }

    public static String getFirstTimeOfDay() throws ParseException {
        Calendar cald = Calendar.getInstance();
        int hour = Calendar.getInstance().get(Calendar.HOUR_OF_DAY);
        cald.add(Calendar.HOUR_OF_DAY, -hour);
        Date date = cald.getTime();
        String s = DateUtils.parseDateToStr("yyyy-MM-dd", date);
        Date date1 = DateUtils.parseDate(s, "yyyy-MM-dd");
        String res = DateUtils.parseDateToStr("yyyy-MM-dd HH:mm:ss", date1);
        return res;
    }
}
